package com.ctshk.sapp.order.ship.controller;


import com.ctshk.common.annotations.OperationLogAnnotation;
import com.ctshk.common.dto.Result;
import com.ctshk.common.enums.OperationLogModel;
import com.ctshk.common.enums.OperationLogType;
import com.ctshk.common.model.PageResponse;
import com.ctshk.common.model.TokenUser;
import com.ctshk.common.web.support.BaseController;
import com.ctshk.rpc.order.ship.dto.*;
import com.ctshk.rpc.order.ship.req.*;
import com.ctshk.rpc.order.ship.service.IShipOrderService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.math.BigDecimal;
import java.util.List;

/**
 * <p>
 * 船票订单 前端控制器
 * </p>
 *
 * @author 刘蕾
 * @since 2021-03-16
 */
@RestController
@RequestMapping("/ship-order")
@Api(value = "船票订单服务",tags = "订单中心")
public class ShipOrderController extends BaseController {
    @DubboReference
    private IShipOrderService iShipOrderService;


    @ApiOperation(value = "核对订单-API产品(珠江)", notes = "核对订单-API产品(珠江)",tags = "订单中心")
    @OperationLogAnnotation(operModul = OperationLogModel.SHIP_ORDER, operType = OperationLogType.ADD, operTitle = "新增珠江船票订单", operDesc = "新增珠江船票订单")
    @PostMapping("/saveApiShipOrder")
    public Result saveApiShipOrder(@RequestBody @Valid ApiShipOrderReq apiShipOrderReq) {
        TokenUser user = getCurrentUser(getRequest());
        return iShipOrderService.saveApiShipOrder(apiShipOrderReq, user);
    }

    @ApiOperation(value = "核对订单-手工产品", notes = "核对订单-手工产品",tags = "订单中心")
    @OperationLogAnnotation(operModul = OperationLogModel.SHIP_ORDER, operType = OperationLogType.ADD, operTitle = "新增船票订单", operDesc = "新增船票订单")
    @PostMapping("/saveShipOrder")
    public Result saveShipOrder(@RequestBody @Valid ShipOrderReq shipOrderReq) {
        TokenUser user = getCurrentUser(getRequest());
        return iShipOrderService.saveShipOrder(shipOrderReq, user);
    }


    @ApiOperation(value = "订单中心-订单详情接口", notes = "订单中心-订单详情接口",tags = "订单中心")
    @OperationLogAnnotation(operModul = OperationLogModel.SHIP_ORDER, operType = OperationLogType.ADD, operTitle = "订单中心-订单详情接口", operDesc = "订单中心-订单详情接口")
    @GetMapping("/order-detail")
    public Result<ShipOrderInfoDTO> queryOrderDetail(@RequestParam(value = "id", required = true)  Long id) {
        return iShipOrderService.queryOrderDetail(id);
    }

    @ApiOperation(value = "订单中心-支付订单查询详情", notes = "订单中心-支付订单查询详情",tags = "订单中心")
    @OperationLogAnnotation(operModul = OperationLogModel.ORDER, operType = OperationLogType.ADD, operTitle = "订单中心-支付订单查询详情", operDesc = "订单中心-支付订单查询详情")
    @GetMapping("/queryPayInfo")
    public Result<ShipOrderInfoDetailDTO> paymentInfoById(@RequestParam(value = "id", required = true)  Long id) {
        //周一调试sql和实体类
        return iShipOrderService.queryOrderDetailInfo(id);
    }

    @ApiOperation(value = "订单列表", notes = "订单中心-船票票订单分页查询列表",tags = "订单中心")
    @OperationLogAnnotation(operModul = OperationLogModel.SHIP_ORDER, operType = OperationLogType.QUERY, operTitle = "订单中心-船票票订单分页查询列表", operDesc = "订单中心-船票票订单分页查询列表")
    @PostMapping("/list")
    public Result<PageResponse<ShipOrderPageDTO>> queryBusLineList(@RequestBody ShipOrderPageReq busOrderPageReq) {
        //周一调试sql和实体类
        PageResponse<ShipOrderPageDTO> response = iShipOrderService.queyList(busOrderPageReq);
        return Result.success(response);
    }

    @ApiOperation(value = "支付页面-下单（收款）", notes = "预订中心船票-支付页面-下单",tags = "订单中心")
    @OperationLogAnnotation(operModul = OperationLogModel.SHIP_ORDER, operType = OperationLogType.ADD, operTitle = "预订中心船票-支付页面-下单", operDesc = "预订中心船票-支付页面-下单")
    @PostMapping(value = "/pay")
    public Result payOrder(@RequestBody @Valid List<ShipOrderCollectionReq> reqList) {
        TokenUser currentUser = getCurrentUser(getRequest());
        return iShipOrderService.payOrder(reqList, currentUser);
    }

    @ApiOperation(value="确认订单", notes="确认订单")
    @OperationLogAnnotation(operModul = OperationLogModel.SHIP_ORDER, operType = OperationLogType.ADD, operTitle = "确认订单", operDesc = "确认订单")
    @PostMapping("/confirm_order")
    public Result<Long> confirmOrder(@RequestBody @Valid ShipProductOrderReq shipProductOrderReq) {
        return iShipOrderService.confirmOrder(shipProductOrderReq,getCurrentUser(getRequest()));
    }

    @ApiOperation(value = "订单中心 船票--待支付取消订单", notes = "订单中心 船票-取消订单",tags = "订单中心")
    @OperationLogAnnotation(operModul = OperationLogModel.SHIP_ORDER, operType = OperationLogType.ADD, operTitle = "订单中心 船票--取消订单", operDesc = "订单中心 船票--取消订单")
    @PostMapping(value = "/cancel-order")
    public Result cancelOrder(@RequestBody ShipCancelOrderReq cancelOrderReq) {
        TokenUser user = getCurrentUser(getRequest());
        return iShipOrderService.cancelOrderBeforePay(cancelOrderReq, user);
    }

    @ApiOperation(value = "订单中心 船票--已支付取消订单", notes = "订单中心 船票-取消订单",tags = "订单中心")
    @OperationLogAnnotation(operModul = OperationLogModel.SHIP_ORDER, operType = OperationLogType.ADD, operTitle = "订单中心 船票--取消订单", operDesc = "订单中心 船票--已支付取消订单")
    @PostMapping(value = "/cancelApprove")
    public Result cancelApprove(@RequestBody ShipCancelOrderReq cancelOrderReq) {
        TokenUser user = getCurrentUser(getRequest());
        return iShipOrderService.cancelApprove(cancelOrderReq, user);
    }

    @ApiOperation(value = "审批中心-审批通过等-审批操作", notes = "订单中心 船票-取消订单",tags = "订单中心")
    @OperationLogAnnotation(operModul = OperationLogModel.SHIP_ORDER, operType = OperationLogType.ADD, operTitle = "订单中心 船票--取消订单", operDesc = "订单中心 船票--取消订单")
    @PostMapping(value = "/cancelOrder")
    public Result cancelOrder(@RequestBody ShipOrderCheckReq shipOrderCheckReq) {
        TokenUser user = getCurrentUser(getRequest());
        return iShipOrderService.cancelOrder(shipOrderCheckReq, user);
    }

    @ApiOperation(value = "订单中心船票-订单操作-确认退款", notes = "订单中心船票-订单操作-确认退款",tags = "订单中心")
    @OperationLogAnnotation(operModul = OperationLogModel.SHIP_ORDER, operType = OperationLogType.UPDATE, operTitle = "订单中心船票-订单中心-确认退款", operDesc = "订单中心船票-订单中心-确认退款")
    @GetMapping("/confirm/refund")
    public Result confirmRefund(@RequestParam(value = "id", required = true) Long id, @RequestParam(value = "refundId", required = true) Long refundId) {
        Long userId =  getCurrentUser(getRequest()).getId();
        return iShipOrderService.confirmRefund(id, refundId, userId);
    }

    @ApiOperation(value = "订单中心 - 操作订单退款记录", notes = "订单中心 - 操作订单退款记录", tags="订单详情-退款记录")
    @OperationLogAnnotation(operModul = OperationLogModel.SHIP_ORDER, operType = OperationLogType.QUERY, operTitle = "订单中心 - 操作订单退款记录", operDesc = "订单中心 - 操作订单退款记录")
    @PostMapping(value = "/refund-list")
    public Result<List<ShipOrderRefundListDTO>> list(@RequestBody ShipOrderRefundReq shipOrderRefundReq){
        return iShipOrderService.list(shipOrderRefundReq);
    }

    @ApiOperation(value="获取退款订单金额", notes="获取退款订单金额", tags="当地玩乐-门票订单")
    @OperationLogAnnotation(operModul = OperationLogModel.SHIP_ORDER, operType = OperationLogType.OTHER, operTitle = "取消订单", operDesc = "取消订单")
    @PostMapping("/get-order-amount")
    public Result<BigDecimal> getOrderAmount(@RequestBody @Valid ShipOrderCheckReq shipOrderCheckReq) {
        return iShipOrderService.getOrderAmount(shipOrderCheckReq,getCurrentUser(getRequest()));
    }

    @ApiOperation(value = "订单中心 - 操作订单保险记录", notes = "订单中心 - 操作订单保险记录", tags="订单详情-保险记录")
    @OperationLogAnnotation(operModul = OperationLogModel.SHIP_ORDER, operType = OperationLogType.QUERY, operTitle = "订单中心 - 操作订单保险记录", operDesc = "订单中心 - 操作订单保险记录")
    @PostMapping(value = "/insurance-list")
    public Result<List<ShipOrderInsuranceDTO>> insuranceRecord(@RequestBody InsuranceReq insuranceReq){
        return iShipOrderService.insuranceRecord(insuranceReq);
    }


    @ApiOperation(value = "订单中心船票-订单操作-删除退款记录", notes = "订单中心船票-订单操作-删除退款记录",tags = "订单中心")
    @OperationLogAnnotation(operModul = OperationLogModel.SHIP_ORDER, operType = OperationLogType.UPDATE, operTitle = "订单中心船票-订单中心-删除退款记录", operDesc = "订单中心船票-订单中心-删除退款记录")
    @GetMapping("/delete/refund")
    public Result deleteRefund(@RequestParam(value = "refundId", required = true) Long refundId) {
        Long userId =  getCurrentUser(getRequest()).getId();
        return iShipOrderService.deleteRefund(refundId, userId);
    }


    @ApiOperation(value="订单中心船票-通知旅客", notes="通知旅客", tags="订单中心船票订单")
    @OperationLogAnnotation(operModul = OperationLogModel.SHIP_ORDER, operType = OperationLogType.ADD, operTitle = "通知旅客", operDesc = "订单中心船票订单-通知旅客")
    @PostMapping("/notice")
    public Result notice(@RequestBody @Valid ShipOrderNoticeReq shipOrderNoticeReq) {
        return iShipOrderService.notice(shipOrderNoticeReq);
    }


    @ApiOperation(value="订单中心船票-获取ATB票的信息", notes="获取ATB票的信息", tags="订单中心船票订单")
    @OperationLogAnnotation(operModul = OperationLogModel.SHIP_ORDER, operType = OperationLogType.ADD, operTitle = "通知旅客", operDesc = "订单中心船票订单-通知旅客")
    @PostMapping("/get-atb-ticket")
    public Result<List<ShipOrderAtbTicketDTO>> getAtbTicket(@RequestBody @Valid ShipTicketReq shipTicketReq) {
        return iShipOrderService.getAtbTicket(shipTicketReq);
    }
}
